package com.n9.qq.android.login.tlv;

import com.n9.qq.util.Util;

import java.util.Objects;

/**
 * @author ice
 * @since 2019/2/12 14:18
 */
public class Tlv0141 extends BaseTlv {
    int h = 1;

    public Tlv0141() {
        this.cmd = 0x0141;
    }

    /**
     * @param simName
     * @param netWorkType
     * @param apnName
     * @return
     */
    public byte[] getData(byte[] simName, int netWorkType, byte[] apnName) {
        if (Objects.isNull(simName)) {
            simName = new byte[0];
        }
        if (Objects.isNull(apnName)) {
            apnName = new byte[0];
        }


        final int simNameLen = simName.length;
        final int apnNameLen = apnName.length;
        int len = 2 + 2 + simNameLen + 2 + 2+ apnNameLen;

        byte[] data = new byte[len];
        int index = 0;
        Util.int16_to_buf(data, index, this.h);
        index += 2;
        Util.int16_to_buf(data, index, simNameLen);
        index += 2;
        System.arraycopy(simName, 0, data, index, simNameLen);
        index += simNameLen;

        Util.int16_to_buf(data, index, netWorkType);
        index += 2;

        Util.int16_to_buf(data, index, apnNameLen);
        index += 2;
        System.arraycopy(apnName, 0, data, index, simNameLen);
        return this.getBufData(data);
    }

}
